import { userProfilesAPI } from "@/request/API";
export default {
    namespaced: true,
    state: {
        //用户信息
        userInfo: {
            nickName: "帅哥",
            coin: 99,
            headImg: require('../../assets/img/monad.png')
        },
        //购物车数量
        cartTotal: 66
    },
    mutations: {
        //修改登陆状态
        chengeuserInfo(state, payload) {
            state.userInfo = payload.userInfo,
                state.cartTotal = payload.cartTotal
        },
        //初始化仓库属性
        inituserInfo(state) {
            state.userInfo = {
                nickName: "帅哥",
                coin: 99,
                headImg: require('../../assets/img/monad.png')
            },
                //购物车数量
                state.cartTotal = 66
        }
    },
    actions: {
        //请求用户信息
        async asyncchengeuserInfo({ commit }) {
            //1.请求用户信息
            let user = await userProfilesAPI();
            // console.log("用户信息", user);
            //2.调用mutations更新用户信息
            commit("chengeuserInfo", user.data)
        }
    }
}